package com.xucranger.ojapi.controller;


import com.xucranger.ojapi.anno.Mylog;
import com.xucranger.ojapi.enity.DTO.AtcoderQueryDTO;
import com.xucranger.ojapi.enity.DTO.CodeforcesQueryDTO;
import com.xucranger.ojapi.enity.DTO.CommonContestQueryDTO;
import com.xucranger.ojapi.enity.DTO.RankDTO;
import com.xucranger.ojapi.enity.DTO.common.PageParamDTO;
import com.xucranger.ojapi.enity.DTO.common.PageResultDTO;
import com.xucranger.ojapi.enity.DTO.common.ResponseDTO;
import com.xucranger.ojapi.enity.VO.CodeforcesVO;
import com.xucranger.ojapi.enity.VO.CommonContestVO;
import com.xucranger.ojapi.enity.VO.RankVO;
import com.xucranger.ojapi.enity.VO.StudentVO;
import com.xucranger.ojapi.enity.domain.Contests;
import com.xucranger.ojapi.enity.domain.Student;
import com.xucranger.ojapi.service.AtcoderService;
import com.xucranger.ojapi.service.CodeforcesService;
import com.xucranger.ojapi.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/common")
@RestController
@Mylog
public class CommonController {

    @Autowired
    CommonService commonService;
    @Autowired
    CodeforcesService codeforcesService;
    @Autowired
    AtcoderService atcoderService;
    @GetMapping("/getlatestcontests/{pagenum}/{pagesize}")
    public ResponseDTO<PageResultDTO<Contests>> getcontests(@PathVariable("pagenum")  Integer pagenum,@PathVariable("pagesize") Integer pagesize){
        return commonService.getcontests(pagenum,pagesize);
    }

    //根据id查询最近比赛
    @GetMapping("/getcontestsbystuid/{pagenum}/{pagesize}/{stuid}")
    public ResponseDTO<PageResultDTO<Contests>> getcontestsbystuid(@PathVariable("pagenum")  Integer pagenum,@PathVariable("pagesize") Integer pagesize,@PathVariable("stuid") String stuid){
        return commonService.getcontestsbyid(pagenum,pagesize,stuid);
    }


    @PostMapping("/participants")
    public ResponseDTO<PageResultDTO<CommonContestVO>>  querystudentbycontestname(@RequestBody CommonContestQueryDTO queryDTO){

        return commonService.querystudentbycontestname(queryDTO);
    }

    //排行榜功能
    @PostMapping("/rank")
    public ResponseDTO<PageResultDTO<RankVO>> rank(@Validated @RequestBody RankDTO rankDTO){
        return commonService.rank(rankDTO);
    }

}
